# This file contains the fastlane.tools configuration
# You can find the documentation at https://docs.fastlane.tools
#
# For a list of all available actions, check out
#
#     https://docs.fastlane.tools/actions
#
# For a list of all available plugins, check out
#
#     https://docs.fastlane.tools/plugins/available-plugins
#

# Uncomment the line if you want fastlane to automatically update itself
# update_fastlane

default_platform(:mac)

bundle_id = CredentialsManager::AppfileConfig.try_fetch_value(:app_identifier)

platform :mac do
  desc "Description of what the lane does"
  lane :custom_lane do
    # add actions here: https://docs.fastlane.tools/actions
  end
end


lane :release do
  setup_ci if ENV['CI']
  match(type: "developer_id", readonly: true)
  Dir.chdir("..") do
    sh("carthage", "update", "--use-xcframeworks")
  end
  build_mac_app(
    configuration: "Release",
    scheme: "PlayCover",
    output_directory: "output",
    output_name: "PlayCover",
    export_method: "developer-id",
    destination: "generic/platform=macOS",
    skip_package_pkg: true,
    xcargs: "FASTLANE=1",
    )
end

lane :nightly do
  setup_ci if ENV['CI']
  match(type: "developer_id", readonly: true)
  Dir.chdir("..") do
    sh("carthage", "update", "--use-xcframeworks")
  end
  carthage(use_xcframeworks: true)
  build_mac_app(
    configuration: "Nightly",
    scheme: "PlayCover",
    output_directory: "output",
    output_name: "PlayCover",
    export_method: "developer-id",
    destination: "generic/platform=macOS",
    skip_package_pkg: true,
    xcargs: "FASTLANE=1",
    )
end

lane :notarize_app do
  notarize(
    package: "output/PlayCover.app",
    api_key_path: "apikey.json",
    bundle_id: bundle_id,
  )
end

lane :notarize_dmg do |options|
  notarize(
    use_notarytool: true,
    package: options[:package],
    api_key_path: "apikey.json",
    bundle_id: bundle_id,
    print_log: true,
    # verbose: true,
  )
end

lane :rename_dmg do
  sh(
    "cd .. && find output -name '*.dmg' -exec mv {} output/PlayCover.dmg \\;",
  )
end
